# nums = [1,1,2]
# nums = set(nums)
# print(list(nums))


# def removeDuplicates(nums):
#     s = 0
#     m = 0
#     n = len(nums)
#     while s < n:
#         if nums[m] == 0:
#             nums.pop(m)
#             nums.append(0)
#         else:
#             m = m+1
#
#         s += 1
#     return nums
#
#
# t = removeDuplicates([0, 0, 1])
# print(t)

# n = 12
# q = list()
# q.append([n,0])
# visited = [False for _ in range(n+1)]
# visited[n] = True
#
# while any(q):
#     num, step = q.pop(0)
#     i = 1
#     tnum = num - i**2
#     while tnum >= 0:
#         if tnum == 0:
#             n = step+1
#         if not visited[tnum]:
#             q.append((tnum,step+1))
#             visited[tnum] = True
#         i += 1
#         tnum = num - i**2
# print(n)

# prices = [7,1,5,3,6,4]
# # # profit = 0
# # # for i in range(1,len(prices)):
# # #     if prices[i] > prices[i-1]:
# # #         profit += prices[i] - prices[i-1]
# # # print(profit)
# #
# # s = sum(b - a for a, b in zip(prices, prices[1:]) if b > a)
# # a = zip(prices, prices[1:])
# # print(list(a))
# # print(s)

# J = "aA"
# S = "bbbb"
# n = 0
# for i in J:
#     a = S.split(i)
#     n += len(a)-1
# print(n)
#
# a = [4,1,2,1,2]
# # b = str(a)
# # b = b.split("2")
# # print(b)
# # print(len(b)-1)
# a.remove(1)
# print(a)


# nums1 = [33,30,4,74,28,68,83,76,43,13,79,75,67,28,45,92,75,70,99,24,20,97,52,80,89,52,66,37,71,12,11,44,62,4,51,87,3,10,35]
# nums2 = [48,9,46,8,98,70,21,98,46,84,27,66,61,40,28,99,75,82,24,40,70,31,40,25,51,13,4,53,86,66,23,69,93,11,91,7]
# n = []
# if len(nums1) >= len(nums2):
#     for i in nums2:
#         if i in nums1:
#             n.append(i)
#             nums1.remove(i)
# else:
#     for i in nums1:
#         if i in nums2:
#             n.append(i)
#             nums2.remove(i)
# print(n)
import numpy as np
# matrix = [[1,2,3],[4,5,6],[7,8,9]]
# n = len(matrix)
# m = len(matrix[0])
# for i in range(n):
#             for j in range(i,m):
#                 matrix[i][j],matrix[j][i] = matrix[j][i],matrix[i][j]
# print(matrix)

def rowcol(board,i):
    rowcount = 0
    colcount = 0
    rowset = set()
    colset = set()
    ans = True
    for j in range(9):
        if board[i][j] != ".":
            colcount += 1
            colset.add(board[i][j])
        if board[j][i] != ".":
            rowcount += 1
            rowset.add(board[j][i])
    if len(colset) != colcount or len(rowset) != rowcount:
        ans = False
    return  ans


def juzheng(board):
    ans = True
    for i,j in center:
        s = set()
        n = 0
        for k in range(-1,2):
            for m in range(-1,2):
                if board[i-k][j-m] != ".":
                    n += 1
                    s.add(board[i-k][j-m])
        if len(s) != n:
            ans = False
    return  ans

board = [[".",".","4",".",".",".","6","3","."],[".",".",".",".",".",".",".",".","."],["5",".",".",".",".",".",".","9","."],[".",".",".","5","6",".",".",".","."],["4",".","3",".",".",".",".",".","1"],[".",".",".","7",".",".",".",".","."],[".",".",".","5",".",".",".",".","."],[".",".",".",".",".",".",".",".","."],[".",".",".",".",".",".",".",".","."]]

center = [(1,1),(1,4),(1,7),(4,1),(4,4),(4,7),(7,1),(7,4),(7,7)]
ans = True
for i in range(9):
    ans = rowcol(board,i)
    if ans is False:
        break
ans = juzheng(board)
print(ans)